
<h2>Events(<%=Date::MONTHNAMES[@month.to_i]%>)</h2>


<%if(!@events.nil?)%>
  <table>
    <tr>
      <th style="padding-right: 15px;">Start Date</th>
      <th style="padding-right: 15px;" width="300">Title</th>
    </tr>
    <%if(@events.size!=0)%>
    <% @events.sort_by {|u| u.start || Time.parse("2000-01-01")}.each do |event| %>

      <%if event.status.to_s=="confirmed" and !event.start.nil? %>
    
      <tr>
        <td><%=h Date.parse(event.start.to_s) %></td>

        <td><%=h event.title %></td>
        <td><%= link_to 'Show',"events/show/#{URI.escape(event.title)}?event_id=#{event.id}&cal_id=#{@cal_id}&cal_title=#{@cal_title}&year=#{@year}&month=#{@month}"%></td>
        <td><%= link_to 'Edit', "events/update/true?event_title=#{event.title}&event_id=#{event.id}&cal_id=#{@cal_id}&cal_title=#{@cal_title}&status=edit&year=#{@year}&month=#{@month}" %></td>
        <td>
          <%if event.get_rrule_hash().nil?%>
            <%= link_to 'Destroy', "events/destroy/?event_title="+event.title+"&cal_title="+@cal_title+
              "&cal_id="+@cal_id+"&event_id="+event.id, :confirm => 'Are you sure?', :method => :delete %>

          <%else%>
            <%= link_to 'Destroy*', "events/range_select/?event_title="+event.title+"&cal_title="+@cal_title+
              "&cal_id="+@cal_id+"&event_id="+event.id+"&start="+Date.parse(event.start.to_s).to_s+"&end="+Date.parse(event.end.to_s).to_s, :method => :range_select %>
          <%end%>
        </td>

      </tr>
      <%end%>
    <% end %>

    <%else%>
       <tr>
        <td colspan="5">No events</td>
       </tr>
    <% end %>

    <tr>
        <td><%= link_to '&lt;&lt;Prev', "/events?title=#{@cal_title}&cal_id=#{@cal_id}&year=#{@year}&month=#{@month.to_i-1}" %></td>
        <td colspan="3"></td>
        <td align="right"><%= link_to 'Next&gt;&gt;', "/events?title=#{@cal_title}&cal_id=#{@cal_id}&year=#{@year}&month=#{@month.to_i+1}" %></td>
      </tr>
  </table>
<%else%>
  <h3>No events</h3>
<% end %>

<%=link_to 'New Event', "events/new?cal_id=#{@cal_id}&status=new" %> &nbsp;&nbsp;
 <%= link_to 'Back to Calendars', "/calendars" %>
 <br>
  <span style="color:gray;font-size:12px;"> * - Repeating Event</span>
